package br.ufrj.dcc.trabxml.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import br.ufrj.dcc.trabxml.manager.BookManager;
import br.ufrj.dcc.trabxml.view.FormMain;

public class LendBook implements ActionListener {
    
    private FormMain form = null;

    public LendBook(FormMain form) {
        this.form = form;
    }   

    public void actionPerformed(ActionEvent e) {
        String isbn = form.getLendISBN();
        int owner = form.getLendOwner();
        BookManager manager = new BookManager();
        try {
            manager.lendBook(form.getSearchGroup(), owner, isbn, form.getLendTitle(), form.getLendPublisher(), form.getLendAuthors(), form.getLendObs());
            form.setLendISBN(null);            
            JOptionPane.showMessageDialog(form, "Livro emprestado com sucesso.", "Info",
                    JOptionPane.INFORMATION_MESSAGE);            
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(form, ex.getMessage(), "Erro",
                    JOptionPane.ERROR_MESSAGE);            
        }
    }

}
